import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import '../../model/danger.dart';
import '../../spaces/recordspace/record_list.dart';
import 'danger_info.dart';

class DangerDetailPage extends StatefulWidget {
  @override
  DangerDetailPage(this.danger);
  final Danger danger;

  @override
  createState() => new DangerDetailPageState();
}

class DangerDetailPageState extends State<DangerDetailPage> {
  late Danger s1;
  bool ifLoad = false;

//  定义底部导航列表
  final List<BottomNavigationBarItem> bottomTabs = [
    new BottomNavigationBarItem(icon: new Icon(Icons.info), label: ('基础信息')),
    new BottomNavigationBarItem(icon: new Icon(Icons.image), label: ('工作记录')),
  ];

  Widget getBody(int i) {
    if (i == 0) return DangerInfoPage(s1, () => {});
    if (i == 1) return RecordListPage(s1.Guid, false);

    return new Container();
  }

  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    s1 = widget.danger;
    ifLoad = true;
    currentPage = getBody(0);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text("问题处理登记单"),
        // leading: Icon(Icons.menu),
      ),
      bottomNavigationBar: new BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: currentIndex,
          items: bottomTabs,
          fixedColor: Colors.blue,
          onTap: (index) {
            setState(() {
              currentIndex = index;
              currentPage = getBody(currentIndex);
            });
          }),
      body: ifLoad
          ? currentPage
          : Center(
              child: SpinKitCircle(
              color: Colors.blue,
            )),
    );
  }
}
